package leetcode.code0155;

import java.util.Stack;

public class MinStack2 extends Solution155 {

	private Stack<int[]> s;
	private int min;

	public MinStack2() {
		s = new Stack<>();
		min = Integer.MAX_VALUE;
	}

	public void push(int val) {
		s.push(new int[] { val, min });
		if (val < min)
			min = val;
	}

	public void pop() {
		min = s.pop()[1];
	}

	public int top() {
		return s.peek()[0];
	}

	public int getMin() {
		return min;
	}

	public static void main(String[] args) {
		int s = 0;
		MinStack2 minStack = new MinStack2();
		minStack.push(-2);
		minStack.push(0);
		minStack.push(-3);
		s = minStack.getMin();
		System.out.println(s);
		minStack.pop();
		s = minStack.top();
		System.out.println(s);
		s = minStack.getMin();
		System.out.println(s);
	}

}
